package com.demo.common.redis.delay;

import org.springframework.data.redis.stream.Cancelable;

import java.time.Duration;

/**
 * <p>
 * 订阅接口类
 * </p>
 *
 * @author molong
 * @date 2022/6/22
 */
public interface Subscription extends Cancelable {

    /**
     * 订阅内容是否正在执行
     * @return {@code true} 如果订阅内容正在执行
     */
    boolean isActive();

    /**
     * Synchronous, <strong>blocking</strong> call returns once the {@link org.springframework.data.redis.stream.Subscription} becomes {@link #isActive()
     * active} or {@link Duration timeout} exceeds.
     *
     * @param timeout must not be {@literal null}.
     * @return {@code true} if the subscription was activated. {@code false} if the waiting time elapsed before task was
     *         activated.
     * @throws InterruptedException if the current thread is interrupted while waiting.
     */
    boolean await(Duration timeout) throws InterruptedException;
}
